package com.vf.admin.client.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.miaodong.entity.SsArea;
import com.vf.admin.miaodong.entity.SsCities;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class SSAreaDao extends BaseDao<SsArea>{

    /**
     * 查询列表
     */
    public List<SsArea> list() {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder(" select * from sys_area where 1=1  ");
        sbStr.append(" ORDER BY id ASC ");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, SsArea.class,null);
    }

    /**
     * 详情
     */
    public SsArea get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder(" select * from sys_area where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, SsArea.class);
    }


    /**
     * 添加/修改
     */
    public void save(SsArea haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = " delete  from sys_area where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    public List<SsArea> findByParentId(Integer parentId){
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from sys_area where parent_id ="+ parentId +" ");

        sbStr.append(" ORDER BY id ASC ");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, SsArea.class);
    }

}
